﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyDuAn.BUS;
using QuanLyDuAn.Report;
using System.Collections;

namespace QuanLyDuAn.GUI
{
    public partial class FrmSearchInterviewer : DevComponents.DotNetBar.Office2007Form
    {
        public String value;
        InterviewerController interview = new InterviewerController();
        DataSet dsName = new DataSet();
        DataSet dsDepartment = new DataSet();
        ArrayList list;
        public FrmSearchInterviewer()
        {
            InitializeComponent();
        }

        public void LoadDataToCollection()
        {
            AutoCompleteStringCollection autoString = new AutoCompleteStringCollection();
            list = new ArrayList();
            list = interview.GetInterviewerName();
            foreach (String Name in list)
            {
                autoString.Add(Name);
            }
            txtInterviewName.AutoCompleteMode = AutoCompleteMode.Append;
            txtInterviewName.AutoCompleteSource = AutoCompleteSource.CustomSource;
            txtInterviewName.AutoCompleteCustomSource = autoString;
        }
        private void FrmSearchInterviewer_Load(object sender, EventArgs e)
        {
            this.dataGridViewX1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            cmbCriterion.Items.Add("Interview Name");
            cmbCriterion.Items.Add("Department");
            cmbDepartment.SelectedItem = "Software I";
            cmbDepartment.Items.Add("Software I");
            cmbDepartment.Items.Add("Software II");
            cmbDepartment.Items.Add("Software III");
            cmbDepartment.Enabled = false;
            txtInterviewName.Enabled = false;
            LoadDataToCollection();
        }
        public void CriterionChange()
        {
            String criterion = cmbCriterion.SelectedItem.ToString();
            if (criterion.CompareTo("Department") == 0)
            {
                MessageBox.Show("Please select Department !");
                txtInterviewName.Enabled = false;
                cmbDepartment.Enabled = true;
                
            }
            else if (criterion.CompareTo("Interview Name") == 0)
            {
                MessageBox.Show("Please select Interview Name");
                
                cmbDepartment.Enabled = false;
                txtInterviewName.Enabled = true;
            }
           
        }

        public int ValueCriterrion()
        {
            int selection;
            String criter = cmbCriterion.Text;
            
            if (criter.CompareTo("") != 0)
            {
                String criterion = cmbCriterion.SelectedItem.ToString();
                if (criterion.CompareTo("Department") == 0)
                {
                    selection = 1;
                }
                else
                {
                    selection = 2;
                }
                return selection;
            }
            else
            {
                selection = 0;
                MessageBox.Show("Please select Criterion! ");
            }
            return selection;
        }

        public void SearchByName()
        {
            String name = txtInterviewName.Text;
            dsName = interview.SearchInterviewByName(name);
            dataGridViewX1.DataSource = dsName.Tables[0];
        }
        public void SearchByDepartment()
        {
            String department = cmbDepartment.SelectedItem.ToString();
            dsDepartment = interview.SearchInterviewByDepartment(department);
            dataGridViewX1.DataSource = dsDepartment.Tables[0];

        }
        private void cmdCriterion_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.CriterionChange();
        }

        

        private void btnReport_Click(object sender, EventArgs e)
        {
            String name = txtInterviewName.Text;
            String department = cmbDepartment.SelectedItem.ToString();
            if (this.ValueCriterrion() == 2)
            {
                FrmInterviewName frm = new FrmInterviewName();
                frm.Visible = true;
                frm.value = name;
                frm.Show();
            }  
        }

        

        private void btnpreview_Click(object sender, EventArgs e)
        {
            String name = txtInterviewName.Text;
            
            int i = this.ValueCriterrion();
            if (i == 2)
            {
                FrmInterviewName frm = new FrmInterviewName();
                frm.value = name;
                frm.Visible = true;
                frm.Show();
            }
            else if (i == 1)
            {
                String department = cmbDepartment.SelectedItem.ToString();
                FrmInterviewDepartment frm = new FrmInterviewDepartment();
                frm.value = department;
                frm.Visible = true;
                frm.Show();
            }
        }

        private void btnSearch_Click_1(object sender, EventArgs e)
        {

            int i = this.ValueCriterrion();
            if (i == 2)
            {
                this.SearchByName();
            }
            else if (i == 1)
            {
               this.SearchByDepartment();
            }
        }
    }
}
